feat: Add for_network() method to configure a custom network#2182
Conversation
Codecov Report❌ Patch coverage is @@ Coverage Diff @@
## main #2182 +/- ##
==========================================
- Coverage 94.01% 93.99% -0.02%
==========================================
Files 163 163
Lines 10403 10442 +39
==========================================
+ Hits 9780 9815 +35
- Misses 623 627 +4 🚀 New features to boost your workflow:
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughClient no longer stores or initializes mirror gRPC channel/stub; mirror access and lifecycle are delegated to Network. Added Client.for_network(network_map, network_name="localhost") which validates shard/realm and constructs a Network from node map. Network defaults to "localhost", adds mirror lifecycle helpers and conditional TLS/port handling. ChangesClient/Network mirror & for_network
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller
participant ClientCtor as Client.for_network()
participant Network as Network
participant Mirror as Mirror gRPC
Caller->>ClientCtor: provide network_map, network_name
ClientCtor->>Network: validate shard/realm, build nodes
ClientCtor-->>Caller: return Client (holds Network)
Caller->>Client: access client.mirror_stub
Client->>Network: network.get_mirror_stub()
Network->>Mirror: create grpc.secure_channel or grpc.insecure_channel
Mirror-->>Network: return ConsensusServiceStub
Network-->>Client: return mirror stub
Caller->>Client: client.close()
Client->>Network: _close()
Network->>Mirror: close channel (if present)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: faea089f-bfc4-4d74-8593-eac6020c6132
📒 Files selected for processing (5)
src/hiero_sdk_python/client/client.pysrc/hiero_sdk_python/client/network.pytck/handlers/sdk.pytests/unit/client_test.pytests/unit/network_test.py
There was a problem hiding this comment.
Actionable comments posted: 7
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 28ae9415-cbc4-4482-99e2-c11e26361eef
📒 Files selected for processing (3)
src/hiero_sdk_python/client/client.pysrc/hiero_sdk_python/client/network.pytests/unit/network_test.py
f8100c0 to
c064829
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/hiero_sdk_python/client/client.py (1)
160-185: 🧹 Nitpick | 🔵 Trivial
for_networkdoes not exposemirror_address; forces callers to rely on the setter.Callers like
tck/handlers/sdk.py(Line 19–20) now construct withfor_network(...)and then assignclient.network.mirror_address = ...afterward. That works becauseClientno longer eagerly initializes the mirror stub, but it leavesfor_networkwithout a first-class way to configure the mirror address at construction time, and any caller that inspectsclient.network.get_mirror_address()before setting it will observe the wrong default (MIRROR_ADDRESS_DEFAULT.get("localhost", "localhost:5600")). Consider exposing it directly:♻️ Proposed fix
- def for_network(cls, network_map: dict[str, AccountId], network_name: str | None = "localhost") -> Client: + def for_network( + cls, + network_map: dict[str, AccountId], + network_name: str | None = "localhost", + mirror_address: str | None = None, + ) -> Client: @@ - nodes = [_Node(account_id, address, None) for address, account_id in network_map.items()] - return cls(Network(network=network_name, nodes=nodes)) + nodes = [_Node(account_id, address, None) for address, account_id in network_map.items()] + return cls(Network(network=network_name, nodes=nodes, mirror_address=mirror_address))Then in
tck/handlers/sdk.py:- client = Client.for_network(network_map=nodes) - client.network.mirror_address = params.mirrorNetworkIp + client = Client.for_network(network_map=nodes, mirror_address=params.mirrorNetworkIp)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 58bdca43-2abb-4ff4-a2a2-2f8c4a0e5d9f
📒 Files selected for processing (5)
src/hiero_sdk_python/client/client.pysrc/hiero_sdk_python/client/network.pytck/handlers/sdk.pytests/unit/client_test.pytests/unit/network_test.py
MonaaEid
left a comment
There was a problem hiding this comment.
I think changing the default network from testnet to localhost is a big behavioral shift, is this will affect the user and developers experience? I ask because I use the testnet network
|
@MonaaEid, that's a nice question. to clarify, this change will not affect users who initialize via The only scenario where backward compatibility is impacted is when a developer calls |
00fec8f to
9c338a3
Compare
localhost and prevent unintended TLS port conversionlocalhost network prevent unintended TLS port conversion
|
Remove the changes to the default network configuration |
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
2c90166 to
04b9165
Compare
localhost network prevent unintended TLS port conversionfor_network() method to configure a custom network
aceppaluni
left a comment
There was a problem hiding this comment.
Can you update the branch when you have a moment?
aceppaluni
left a comment
There was a problem hiding this comment.
Can you update your branch?
Thank you
Description:
This PR remove unintended tls port converstion for the non-tls:port and tls:port for non self-hosted network. Also introduce the
for_network()method to create network usingNodeobjectChanges:
Client.for_networkto ensure the internal Network instance defaults to a non-hosted label.mainnet,testnet, orpreviewnet.Related issue(s):
Fixes #2181
Notes for reviewer:
Checklist